package com.bestescortbedsystem.controller;

import com.bestescortbedsystem.entity.*;
import com.bestescortbedsystem.service.OrderService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: LuXi
 * @Date: 2021/3/1 16:55
 * @Description:
 */
@Api(value = "订单模块")
@RestController
@RequestMapping("order")
public class OrderController {
    @Resource
    private OrderService orderService;

    /**
     * 返回订单信息
     * @return
     */
    @ApiOperation(value = "获取订单", notes = "所有订单列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orderSearch",value = "查询条件",required = false,dataTypeClass = OrderSearch.class),
            @ApiImplicitParam(name = "pageNum",value = "当前页码",required = true,dataTypeClass = Integer.class)
    })
    @RequestMapping("info")
    public Map<String,Object> info(OrderSearch orderSearch,@RequestParam(defaultValue = "5")Integer pageSize, @RequestParam(defaultValue = "1")Integer pageNum){
        Map<String,Object> map = new HashMap<>();
        try{
            PageInfo<SesUserOrder> info = orderService.info(orderSearch,pageSize,pageNum);
            List<SesHospitalinfo> hospitals = orderService.hospitalInfo();
            List<SesHospitalinfoDepartment> departments = orderService.departmentInfo();
            map.put("result",true);
            map.put("list",info.getList());
            map.put("pageInfo",info);//分页
            map.put("size",info.getList().get(0).getSize());//总订单数
            map.put("hospitals",hospitals);//医院
            map.put("departments",departments);//科室
        }catch (Exception e){
            map.put("result",false);
        }finally {
            return map;
        }
    }

    /**
     * 删除订单信息
     * @return
     */
    @ApiOperation(value = "删除订单", notes = "删除一个订单")
    @ApiImplicitParam(name = "userorderid",value = "用户ID",required = true,dataTypeClass = Long.class)
    @RequestMapping("delete")
    public Map<String,Object> delete(Long userorderid){
        Map<String,Object> map = new HashMap<>();
        try{
            orderService.deleteOrder(userorderid);
            map.put("result",true);
        }catch (Exception e){
            map.put("result",false);
        }finally {
            return map;
        }
    }

    /**
     * 获取订单详情信息
     * @return
     */
    @ApiOperation(value = "获得订单详情", notes = "获得单个订单详情")
    @ApiImplicitParam(name = "userorderid",value = "用户ID",required = true,dataTypeClass = Long.class)
    @RequestMapping("XiangQing")
    public Map<String,Object> xiangQing(Long userorderid){
        Map<String,Object> map = new HashMap<>();
        try{
            Map<String, Object> result = orderService.orderXiangQing(userorderid);
            map.put("result",true);
            map.put("map",result);
        }catch (Exception e){
            map.put("result",false);
        }finally {
            return map;
        }
    }
}
